package com.social.controller;

import com.alibaba.fastjson.JSON;
import com.social.pojo.Post;
import com.social.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 岗位管理
 */
@Controller
@RequestMapping("Post")
public class PostController {
    /**
     * Post 业务层
     */
    @Autowired
    private PostService postService;

    /**
     * 查所有
     *
     * @param session 作用域
     * @return 查询状态
     */
    @RequestMapping(value = "selectAll", produces = "text/application;charset=utf-8")
    @ResponseBody
    public String selectAll(HttpSession session) {
        try {
            List<Post> posts = postService.selectAll();
            session.setAttribute("post", posts);
        } catch (Exception e) {
            return JSON.toJSONString(false);
        }
        return JSON.toJSONString(true);
    }
}
